<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <input type="text" placeholder="员工姓名" v-model="emp.name">
    <input type="text" placeholder="员工工资" v-model="emp.salary">
    <input type="text" placeholder="员工工作" v-model="emp.job">
    <input type="button" value="添加" @click="f()">
    <table border="1">
        <caption>员工列表</caption>
        <tr>
            <th>姓名</th>
            <th>工资</th>
            <th>工作</th>
            <th>操作</th>
        </tr>
        <tr v-for="(emp,i) in arr">
            <td>{{emp.name}}</td><td>{{emp.salary}}</td><td>{{emp.job}}</td>
            <td><input type="button" value="删除" @click="del(i)"></td>
        </tr>
    </table>
</div>
<script src="js/vue.js"></script>
<script>
    Vue.createApp({
        data() {
            return {
                emp:{name:"",salary:"",job:""},
                arr: [{name: "张三", salary: 3000, job: "销售"},
                    {name: "李四", salary: 4000, job: "人事"}]
            }
        },
        methods: {
            f() {
                let newEmp = {name:this.emp.name,salary:this.emp.salary,job:this.emp.job};
                this.arr.push(newEmp);
            },
            del(i){
                //从数组中删除对象 splice(下标,数量)
                this.arr.splice(i,1);
            }
        },
    }).mount("body>div");
</script>
</body>
</html>